package com.shishuo.cms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shishuo.cms.dao.UserRoleDao;
import com.shishuo.cms.entity.UserRoleEntity;
import com.shishuo.cms.entity.vo.PageVo;

@Service
public class UserRoleService extends BaseService<UserRoleEntity, Long> {

	private UserRoleDao userRoleDao;

	@Autowired
	public void setUserRoleDao(UserRoleDao userRoleDao) {
		setBaseDao(userRoleDao);
		this.userRoleDao = userRoleDao;
	}

	public List<UserRoleEntity> getRoles(int status) {
		return userRoleDao.getRoles(status);
	}

	public int updateRoleStatus(int id, int status) {
		return userRoleDao.updateRoleStatus(id, status);
	}

	public PageVo<UserRoleEntity> getAllListPage(int pageNum) throws Exception {
		PageVo<UserRoleEntity> pageVo = new PageVo<UserRoleEntity>(pageNum);
		List<UserRoleEntity> list = this.getAllList(pageVo.getOffset(), pageVo.getRows());
		pageVo.setList(list);
		pageVo.setCount(this.getAllListCount());
		return pageVo;
	}

	public UserRoleEntity getByRoleName(String roleName) {
		return userRoleDao.getByRoleName(roleName);
	}
}
